<template>
  <Form autocomplete="off" class="user-form" ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="0">

    <FormItem label="" prop="code">
          <tableExport @changeData="changeData"></tableExport>
          <input type="hidden" v-model="formValidate.code"   placeholder="请导入符合要求的数据" />
    </FormItem>
    <div class="ivu-text-center mt20">
      <Button  @click="handleSubmit('formValidate')">提交</Button>
    </div>
  </Form>
</template>
<script>
import {imeiImportAdd} from '@/api/imeiImport';
import tableExport from '../export/index';
export default {
 components:{tableExport},
  data () {
    return {
      pwdType:'text',
      formValidate: {
        code:[],
      },
      ruleValidate: {
        code: [
          {   message: '设备编码不能为空，请按照要求导入设备编码', trigger: 'blur' },
        ],
      }
    }
  },
  methods: {
    changeData(data){
      this.formValidate.code=data;
    },
    async Add(){
      return  await imeiImportAdd(this.formValidate);
    },
    handleSubmit (name) {
      this.$refs[name].validate(async (valid) => {
        if (valid) {
        let res = await this.Add()
          if(_.get(res,'code')==0){
            this.$Message.success(this.isAdd?'新增成功':'修改成功');
            this.$emit('success');
          }else{
            this.$Message.error(_.get(res,'message'));
          }

        } else {
          // this.$Message.error('Fail!');
        }
      })
    },
    handleReset (name) {
      this.$refs[name].resetFields();
    }
  }
}
</script>
<style scoped lang="less">

</style>
